﻿namespace HuaWei.YZ
{
    using HuaWei.CommClass;
    using HuaWei.DAI;
    using System;
    using System.Collections;

    public static class SPGLUtils
    {
        public static bool RobackData(string loginId, string bdid, string qcid, bool isYzData)
        {
            IDataAccess ida = DBHelp.IniIDA();
            ArrayList sqlList = new ArrayList();
            string str = "";
            string tableName = "";
            foreach (TableInfo info in SysDtManager.IniJLTableList())
            {
                tableName = info.TableName;
                str = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", tableName, bdid, qcid);
                sqlList.Add(str);
                if (!isYzData)
                {
                    str = string.Format("delete from {0}2 where bdid='{1}' and qcid='{2}'", tableName, bdid, qcid);
                }
                else
                {
                    str = string.Format("delete from {0}2 where bdid='{1}' and qcid='{2}' sid in (select id from zzjgxx where (levelcode = '{3}' or levelCode not like '{3}%') and xmid='{4}')", new object[] { tableName, bdid, qcid, GParams.LevelCode, GParams._XMID });
                }
                sqlList.Add(str);
            }
            str = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF1", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF2", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQZFZS", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", "REP_GCBG", bdid, qcid);
            sqlList.Add(str);
            if (sqlList.Count > 0)
            {
                ida.BeginTrans();
                try
                {
                    DBHelp.ExeSql(ida, sqlList);
                    ida.Commit();
                }
                catch (Exception)
                {
                    ida.RollBack();
                }
            }
            return true;
        }
    }
}

